package cn.com.guanying.android.ui;

import java.util.ArrayList;

import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import cn.com.guanying.R;
import cn.com.guanying.android.ui.adapter.ImageAdapter;
import cn.com.guanying.android.ui.adapter.MovieItemAdapter;
import cn.com.guanying.android.ui.dialogs.GuanyingDialog;
import cn.com.guanying.android.ui.view.FlowIndicator;
import cn.com.guanying.android.ui.view.HomeHeaderView;
import cn.com.guanying.android.ui.view.ViewFlow;
import cn.com.guanying.javacore.v11.models.FilmInfo;

public class HomeActivity extends BaseActivity implements OnItemClickListener{
	
	ListView mHomeList;

	public ViewFlow mViewflow;
	private MovieItemAdapter mMovieItemAdapter;
	public FlowIndicator mFlowIndicator;
	HomeHeaderView mHomeHeaderView;

	public void doFindView() {
		mHomeList = (ListView) findViewById(R.id.list_movie);
		mHomeList.setOnItemClickListener(this);
		mHomeHeaderView =new HomeHeaderView(this,this);
	}

	public void doInit() {
		ArrayList<Integer> imageIds = new ArrayList<Integer>();
		imageIds.add(R.drawable.moive_1);
		imageIds.add(R.drawable.moive_2);
		imageIds.add(R.drawable.moive_3);
		imageIds.add(R.drawable.moive_4);
		imageIds.add(R.drawable.moive_5);
		imageIds.add(R.drawable.moive_6);
		imageIds.add(R.drawable.moive_7);
		ImageAdapter imageAdapter = new ImageAdapter(imageIds);
		mHomeHeaderView.setAdapter(imageAdapter);
		mHomeList.addHeaderView(mHomeHeaderView.getView());
		ArrayList<FilmInfo> a = new ArrayList<FilmInfo>();
		FilmInfo mi = new FilmInfo();
		a.add(mi);
		a.add(mi);
		a.add(mi);
		a.add(mi);
		a.add(mi);
		a.add(mi);
		a.add(mi);
		mMovieItemAdapter = new MovieItemAdapter(this);
		mMovieItemAdapter.setmMovieList(a);
		mHomeList.setAdapter(mMovieItemAdapter);
		
	}
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK){
			showExitDialog();
			return true;
		}
		return false;
	}

	protected void onLogicEventUI(Object sender, int eventId, Object[] datas) {
		
		
	}
	
	public void exit(){
		android.os.Process.killProcess(android.os.Process.myPid());
	}

	public void showExitDialog(){
		final GuanyingDialog gyDlg = new GuanyingDialog(this);
		gyDlg.setButton2(R.string.quxiao, new OnClickListener() {
			public void onClick(View v) {
				gyDlg.dismiss();
			}
		});
		gyDlg.setButton1(R.string.queding, new OnClickListener() {
			public void onClick(View v) {
				exit();
				gyDlg.dismiss();
			}
		});
		gyDlg.setInfo(R.string.tuichutishi);
		gyDlg.show();
	}
	@Override
	protected int getContentView() {
		return R.layout.activity_home;
	}
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		Intent intent = new Intent(this,MovieDetailsActivity.class);
		startActivity(intent);
	}
	
}
